package com.ruoyi.web.controller.fire;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fire.domain.FireDispatch;
import com.ruoyi.fire.service.IFireDispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出警Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/fire/dispatch")
public class FireDispatchController extends BaseController
{
    @Autowired
    private IFireDispatchService fireDispatchService;

    /**
     * 查询出警列表
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(FireDispatch fireDispatch)
    {
        startPage();
        List<FireDispatch> list = fireDispatchService.selectFireDispatchList(fireDispatch);
        return getDataTable(list);
    }

    /**
     * 导出出警列表
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:export')")
    @Log(title = "出警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FireDispatch fireDispatch)
    {
        List<FireDispatch> list = fireDispatchService.selectFireDispatchList(fireDispatch);
        ExcelUtil<FireDispatch> util = new ExcelUtil<FireDispatch>(FireDispatch.class);
        util.exportExcel(response, list, "出警数据");
    }

    /**
     * 获取出警详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fireDispatchService.selectFireDispatchById(id));
    }

    /**
     * 新增出警
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:add')")
    @Log(title = "出警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FireDispatch fireDispatch)
    {
        return toAjax(fireDispatchService.insertFireDispatch(fireDispatch));
    }

    /**
     * 修改出警
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:edit')")
    @Log(title = "出警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FireDispatch fireDispatch)
    {
        return toAjax(fireDispatchService.updateFireDispatch(fireDispatch));
    }

    /**
     * 删除出警
     */
    @PreAuthorize("@ss.hasPermi('fire:dispatch:remove')")
    @Log(title = "出警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fireDispatchService.deleteFireDispatchByIds(ids));
    }
}
